package com.mr.example3.friend;

import java.io.IOException;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

/*
 * 1.输入数据：(好友	用户)，(好友	用户)
 * 		(B	A),(C	A),(D	A),(F	A),(E	A),(O	A)
 * 		(B	E)
 * 		(B	F)
 *
 * 2.输出数据：(好友	用户，用户)
 * 		（B	A,E,F）
 */

public class Example3Reducer1 extends Reducer<Text, Text, Text, Text>{

	@Override
	protected void reduce(Text key, Iterable<Text> values, Reducer<Text, Text, Text, Text>.Context context)
			throws IOException, InterruptedException {

		StringBuffer sb = new StringBuffer();

		for (Text value : values) {

			sb.append(value.toString() + ",");

		}

		context.write(key, new Text(sb.deleteCharAt(sb.length() - 1).toString()));

	}

}
